import java.util.Scanner;

public class Test_5 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str = scanner.nextLine();
        //把字符串转换为字符数组
        char[] chars =str.toCharArray();
        //记录次数
        int countNum=0;
        for(int i=0;i<chars.length-1;i++){
            if(chars[i]=='a'&&chars[i+1]=='b'){
                countNum++;
            }
        }

        System.out.println("countNum="+countNum);
    }
}
